import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:share_fit/app/models/base_model.dart';

class SleepHistory extends BaseModel {
  late String label;
  List<SleepItem> sleepItems = [];

  @override
  bool from(Map<dynamic, dynamic> map) {
    label = map['calendarTime'] ?? '';
    List list = map['list'] ?? [];

    for (var value in list) {
      sleepItems.add(SleepItem(sleepTime: value['sleepTime'], sleepType: value['sleepType']));
    }
    return true;
  }

  get sleepTimeSum => {sleepItems.isNotEmpty ? sleepItems.map((e) => e.sleepTime).reduce((value, element) => value + element) : ''};

  @override
  // TODO: implement props
  List<Object?> get props => [];
}

class SleepItem {
  int sleepTime;
  int sleepType;
  late Color color = getItemColor();

  SleepItem({this.sleepTime = 0, this.sleepType = 0});

  Color getItemColor() {
    if (sleepType == 1) {
      return const Color.fromRGBO(149, 95, 252, 1);
    } else if (sleepType == 2) {
      return Colors.red.withOpacity(0.8);
    } else if (sleepType == 3) {
      return Colors.green.withOpacity(0.8);
    } else {
      return Colors.blue.withOpacity(0.8);
    }
  }
}
